//
//  BRHomeCell.m
//  MyBaseProject
//
//  Created by 任波 on 2017/9/14.
//  Copyright © 2017年 任波. All rights reserved.
//

#import "BRHomeCell.h"
#import "BRHomeModel.h"

@implementation BRHomeCell

- (instancetype)init {
    if (self = [super init]) {
        self.imageView.hidden = NO;
        self.titleLabel.hidden = NO;
        self.descLabel.hidden = NO;
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    __weak typeof(self) weakSelf = self;
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(10);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(weakSelf.imageView.mas_right).with.offset(10);
        make.height.mas_equalTo(20);
    }];
    [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.titleLabel.mas_bottom).with.offset(5);
        make.left.mas_equalTo(weakSelf.imageView.mas_right).with.offset(10);
        make.height.mas_equalTo(20);
    }];
}

- (void)setModel:(BRHomeModel *)model {
    _model = model;
    self.imageView.image = [UIImage imageNamed:model.imageName];
    self.titleLabel.text = model.title;
    self.descLabel.text = model.desc;
}

- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc]init];
        _imageView.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:_imageView];
    }
    return _imageView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.backgroundColor = [UIColor clearColor];
        _titleLabel.font = [UIFont systemFontOfSize:16.0f];
        _titleLabel.textColor = RGB_HEX(0x464646, 1.0f);
        [self.contentView addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (UILabel *)descLabel {
    if (!_descLabel) {
        _descLabel = [[UILabel alloc]init];
        _descLabel.backgroundColor = [UIColor clearColor];
        _descLabel.font = [UIFont systemFontOfSize:14.0f];
        _descLabel.textColor = RGB_HEX(0x999999, 1.0f);
        [self.contentView addSubview:_descLabel];
    }
    return _descLabel;
}

@end
